/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.server.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.lucava.boatskeeper.shared.dto.UserDto;

/**
 *
 * @author glenn
 */
public class MockUserDao {

    final static Map<Integer, UserDto> users = new HashMap<Integer, UserDto>();

    static {
        for (int i = 0; i < 10; i++) {
            UserDto u = new UserDto();
            u.setId(i);
            u.setLogin("user" + i);
            u.getRole().setName("role" + i);
            u.getRole().setId(i);
            users.put(i, u);
        }
    }

    public static void add(UserDto u) {
        u.setId(users.size() - 1);
        u.getRole().setName(MockRoleDao.get(u.getRole().getId()).getName());

        users.put(u.getId(), u);
    }

    public static void save(UserDto u) {
        users.get(u.getId()).setLogin(u.getLogin());
        users.get(u.getId()).getRole().setName(MockRoleDao.get(u.getRole().getId()).getName());
        users.get(u.getId()).getRole().setId(u.getRole().getId());
    }

    public static void delete(UserDto u) {

        users.remove(u.getId());
    }

    public static UserDto get(Integer id) {
        return users.get(id);
    }

    public static List<UserDto> getAll() {

        return new ArrayList<UserDto>(users.values());
    }
}
